package com.aidex.biz.controller;

import com.aidex.biz.domain.SearchInfoDetails;
import com.aidex.biz.service.SearchInfoDetailsService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品链接列Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-03-31
 */
@RestController
@RequestMapping("/biz/bizSearchInfoDetails")
public class SearchInfoDetailsController extends BaseController
{
    @Autowired
    private SearchInfoDetailsService searchInfoDetailsService;

    /**
     * 查询产品链接列列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSearchInfoDetails:list')")
    @GetMapping("/list")
    public R<PageInfo> list(SearchInfoDetails searchInfoDetails, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                searchInfoDetails.setCompanyId(null);
        }else{
                     searchInfoDetails.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        searchInfoDetails.setPage(new PageDomain(request, response));
        return R.data(searchInfoDetailsService.findPage(searchInfoDetails));
    }

    /**
     * 获取产品链接列详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSearchInfoDetails:query')")
    @GetMapping(value = "/{id}")
    public R<SearchInfoDetails> detail(@PathVariable("id") String id)
    {
        return R.data(searchInfoDetailsService.get(id));
    }

    /**
     * 新增产品链接列
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSearchInfoDetails:add')")
    @Log(title = "产品链接列", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  SearchInfoDetails searchInfoDetails)
    {
        return R.status(searchInfoDetailsService.save(searchInfoDetails));
    }

    /**
     * 修改产品链接列
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSearchInfoDetails:edit')")
    @Log(title = "产品链接列", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated SearchInfoDetails searchInfoDetails)
    {
        return R.status(searchInfoDetailsService.save(searchInfoDetails));
    }


    /**
     * 删除产品链接列
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSearchInfoDetails:remove')")
    @Log(title = "产品链接列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(searchInfoDetailsService.deleteSearchInfoDetailsByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSearchInfoDetails:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(searchInfoDetailsService.findMaxSort(new SearchInfoDetails()));
    }

    /**
     * 导出产品链接列列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSearchInfoDetails:export')")
    @Log(title = "产品链接列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(SearchInfoDetails searchInfoDetails)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    searchInfoDetails.setCompanyId(null);
            }else{
                         searchInfoDetails.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<SearchInfoDetails> list = searchInfoDetailsService.findList(searchInfoDetails);
        ExcelUtil<SearchInfoDetails> util = new ExcelUtil<SearchInfoDetails>(SearchInfoDetails.class);
        return util.exportExcel(list, "产品链接列数据");
    }

}
